package com.stars.questions.commonQuestion.config.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.stars.base.entity.BaseEntity;
import com.stars.util.date.DateFormatUtils;
import org.apache.ibatis.type.JdbcType;

import java.util.Date;
import java.util.List;

/**
 * 问卷配置实体
 * @author : moon
 * @date :  2024/6/29 16:54
 */
@TableName("QUESTION_COMMON_CONFIG")
public class QuestionsCommonConfig extends BaseEntity {

    private String id;

    @TableField("YEAR")
    private String year;

    @TableField("TITLE")
    private String bt;

    @TableField(value="NUM")
    private Integer num;

    @TableField(value = "PUBLISH",jdbcType = JdbcType.DECIMAL)
    private Integer publish;

    @TableField("STARTDATE")
    private Date startDate;

    @TableField("ENDDATE")
    private Date endDate;

    @TableField(exist = false)
    private String[] entryDate;

    @TableField(exist = false)
    private List<QuestionsCommonConfigSub> questions;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    public String getBt() {
        return bt;
    }

    public void setBt(String bt) {
        this.bt = bt;
    }

    public Integer getNum() {
        return num;
    }

    public void setNum(Integer num) {
        this.num = num;
    }

    public Integer getPublish() {
        return publish;
    }

    public void setPublish(Integer publish) {
        this.publish = publish;
    }

    public Date getStartDate() {
        if (entryDate != null && entryDate.length > 0) {
            return DateFormatUtils.parseDate(entryDate[0]);
        }
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        if (entryDate != null && entryDate.length > 1) {
            return DateFormatUtils.parseDate(entryDate[1]);
        }
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public String[] getEntryDate() {
        if(entryDate==null||entryDate.length<1){
            entryDate = new String[2];
            entryDate[0] = DateFormatUtils.formatDate(startDate);
            entryDate[1] = DateFormatUtils.formatDate(endDate);
        }
        return entryDate;
    }

    public void setEntryDate(String[] entryDate) {
        this.entryDate = entryDate;
    }

    public List<QuestionsCommonConfigSub> getQuestions() {
        return questions;
    }

    public void setQuestions(List<QuestionsCommonConfigSub> questions) {
        this.questions = questions;
    }
}
